import { RouteObject as RRouteObject, useRoutes, Navigate } from 'react-router-dom'
import Layout from '@/layouts'
import Home from '@/pages/home'
import Settings from '@/pages/settings'
import Log from '@/pages/log'
import About from '@/pages/about'

const routes = [
	{
		path: '/login',
		element: <Layout layoutApply='loginPage' />,
	},
	{
		path: '/',
		element: <Layout layoutApply='mainPage' />,
		children: [
			{
				index: true, // 默认页面
				element: <Navigate to='/home' />,
				meta: {
					requireAuth: false,
					title: '工作台',
					key: 'home'
				}
			},
			{
				path: 'home',
				element: <Home />,
				meta: {
					requireAuth: false,
					title: '工作台',
					key: 'home'
				}
			},
			{
				path: 'settings',
				element: <Settings />,
				meta: {
					requireAuth: false,
					title: '设置',
					key: 'settings'
				}
			},
			{
				path: 'log',
				element: <Log />,
				meta: {
					requireAuth: false,
					title: '日志',
					key: 'log'
				}
			},
			{
				path: 'about',
				element: <About />,
				meta: {
					requireAuth: false,
					title: '关于',
					key: 'about'
				}
			},
		]
	},
	{
		path: '*',
		element: <Navigate to='/home' />
	}
]

const Router = () => useRoutes(routes as RRouteObject[])

export default Router
